import { baseUrlApi, requestClient, type Result } from '#/api/request';
// 角色数据类型
export interface RolseData {
  name: string; // 角色名称
  type: string; // 角色类型
  remark: string; // 角色描述
  status: number; // 状态;1:启用;0:禁用
  id?: number;
}

/** 角色列表 */
export const getAdminRoles = (params?: { limit: number; page: number }) => {
  return requestClient.get<Result>(baseUrlApi('/admin/roles'), { params });
};

/**
 * 添加角色
 * @param data
 * @returns
 */
export const postAdminRoles = (data?: RolseData) => {
  return requestClient.post<Result>(baseUrlApi('/admin/roles'), data);
};

/**
 * 获取角色信息
 * @param id
 * @returns
 */
export const getAdminRolesInfo = (id: number) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/roles/${id}`));
};

/**
 * 编辑角色
 * @param id
 * @param data
 * @returns
 */
export const putAdminRoles = (id: number, data?: RolseData) => {
  return requestClient.put<Result>(baseUrlApi(`/admin/roles/${id}`), data);
};

/**
 * 删除角色
 * @param id
 * @returns
 */
export const deleteAdminRoles = (id: number) => {
  return requestClient.delete<Result>(baseUrlApi(`/admin/roles/${id}`));
};

/**
 * 获取角色后台菜单授权信息
 * @param id
 * @returns
 */
export const getAdminRolesAuthorize = (id: number) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/roles/${id}/authorize`));
};

/**
 * 提交角色后台菜单授权信息
 * @param id 角色id
 * @param data 数据
 * @returns
 */
export const putAdminRolesAuthorize = (id: number, data: { ids: object }) => {
  return requestClient.put<Result>(
    baseUrlApi(`/admin/roles/${id}/authorize`),
    data,
  );
};

/**
 * 获取角色api授权信息
 * @param id
 * @returns
 */
export const getAdminRolesApiAuthorize = (id: number) => {
  return requestClient.get<Result>(
    baseUrlApi(`/admin/roles/${id}/api/authorize`),
  );
};

/**
 * 提交角色后台菜单授权信息
 * @param id 角色id
 * @param data 数据
 * @returns
 */
export const putAdminRolesApiAuthorize = (
  id: number,
  data: { ids: object; role_id: number },
) => {
  return requestClient.put<Result>(
    baseUrlApi(`/admin/roles/${id}/api/authorize`),
    data,
  );
};
